package edu.ynu.e_platform.entities;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import edu.ynu.e_platform.common.entity.LogicEntity;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import javax.persistence.criteria.CriteriaBuilder;
import java.util.Set;

/**
 * @author manwen Yang
 */
@Entity
@Getter
@Setter
@JsonIgnoreProperties(value = {"handler","hibernateLazyInitializer","fieldHandler"})
@Where(clause = "isDeleted = 0")  //逻辑删除,过滤掉删除标记不为0的
public class Item extends LogicEntity {

    @Column
    private String itemName;

    @Column
    private String itemImg;

    /**
     * 暂定类别 0 电脑办公; 1 家电; 2 食品酒饮; 3 服装; 4 手机; 5 数码; 6 玩具乐器
     * */
    @Column
    private Integer itemType;

    @Column
    private String description;

    @Column
    private Double price;

    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnoreProperties(value = {"items","shops"})
    private Business business;

    @OneToOne(fetch = FetchType.LAZY)
    @JsonIgnoreProperties(value = {"item","order"})
    private LineItem lineItem;

    @OneToMany(mappedBy = "item",
            fetch = FetchType.LAZY,
            orphanRemoval = true,
            cascade = CascadeType.ALL)
    @JsonIgnoreProperties(value = {"item"})
    private Set<ShopItem> shopItems;
}
